package gtkwire.widget;

import gtkwire.*;
import gtkwire.listener.connector.WindowDestroyedListenerFilter;
import gtkwire.listener.WindowDestroyedListener;
import gtkwire.widget.utils.GtkWindowType;

/**
*Toplevel which can contain other widgets.
*Documentation for this class is from the gtk+ .c file that this class binds to. See original file for copyrights.
*/
public class GtkWindow extends GtkBin
{
	/**
	*Window type, either GtkWindowType.TOPLEVEL or GtkWindowType.POPUP.
	*/
	private GtkWindowType type = GtkWindowType.TOPLEVEL;
	
	public GtkWindow( GtkWindowType type )
	{
		super();
		this.widgetType = WT_GtkWindow;
		this.type = type;
		gtkCreate();
	}

	/**
	* Constructor with possibility of setting window type. This is the only time it can be set.
	*/
	public GtkWindow( String name, GladeKey key )
	{
		super( name, key );
		this.widgetType = WT_GtkWindow;
	}

	/**
	* Sets type when created.
	*/
	protected String[] getCreateData()
	{ 
		String[] cmsg = { type.getMode() };
		return cmsg;
	}

	/**
	*Returns window's type.
	*/
	public GtkWindowType getType(){ return type; }

	/**
	*Asks to iconify (i.e. minimize) the specified window. 
	*Note that you shouldn't assume the window is definitely iconified afterward, 
	*because other entities (e.g. the user or window manager) could deiconify it again, or there may not be a window manager
	*/
	public void iconify(){ app().sendCommand( name, GTKWireCommand.ICONIFY ); }

	/**
	*Asks to deiconify (i.e. unminimize) the specified window. 
	*Note that you shouldn't assume the window is definitely deiconified afterward, 
	*because other entities (e.g. the user or window manager) could iconify it again 
	*before your code which assumes deiconification gets to run.
	*/
	public void deiconify(){ app().sendCommand( name, GTKWireCommand.DEICONIFY ); }

	/**
	*Asks to maximize window, so that it becomes full-screen.
	*Note that you shouldn't assume the window is definitely maximized afterward,
	*because other entities (e.g. the user or window manager) 
	*could unmaximize it again, and not all window managers support maximization.
	*/
	public void maximize(){	app().sendCommand( name, GTKWireCommand.MAXIMIZE ); }

	/**
	*Asks to unmaximize window.
	*Note that you shouldn't assume the window is definitely unmaximized afterward,
	*because other entities (e.g. the user or window manager) could maximize it again,
	*and not all window managers honor requests to unmaximize.
	*/
	public void unmaximize(){ app().sendCommand( name, GTKWireCommand.UNMAXIMIZE ); }

	/**
	*Sets the title of the GtkWindow. The title of a window will be displayed in its title bar; 
	*on the X Window System, the title bar is rendered by the window manager, 
	*so exactly how the title appears to users may vary according to a user's exact configuration.
	*/
	public void setTitle( String title ){ app().sendCommand( name, GTKWireCommand.SET_TITLE, title ); }

	/**
	*Sets whether the user can resize a window. Windows are user resizable by default.
	*/
	public void setResizable( boolean val ){ app().sendCommand( name, GTKWireCommand.SET_RESIZABLE, val ); }

	/**
	*Set the decorated property to FALSE using this function.
	*GTK+ will do its best to convince the window manager not to decorate the window.
	*/
	public void setDecorated( boolean val )
	{
		 app().sendCommand( name, GTKWireCommand.SET_DECORATED, val );
	}

	/**
	* Adds listener that gets notified if window is destroyed. 
	*/
	public void addDestroyListener( WindowDestroyedListener listener )
	{
		WindowDestroyedListenerFilter wl = new WindowDestroyedListenerFilter( listener );
		wl.addFilteringName( name );
		app().addListener( wl );
		connectSignals( wl.getSignals() );
	}

}//end class